package com.telnetnz.ticketdesk.bean;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.telnetnz.ticketdesk.bean.misc.OperationLogObject;
import com.telnetnz.ticketdesk.dao.entity.UserEntity;
import com.telnetnz.ticketdesk.service.OperationLogService;
import com.telnetnz.ticketdesk.service.ProjectToUserService;

public class User extends UserEntity implements Serializable,
		OperationLogObject {

	private static final long serialVersionUID = 329206067661215452L;

	public List<ProjectToUser> getProjectUsers() {
		return ProjectToUserService.getByUserId(getId());
	}

	public List<OperationLog> getOperationLogs() {
		return OperationLogService.getLogsByPageAndCondition(
				0, 
				10, 
				OperationLogService.ORDERBY_TIME, 
				0, 
				0L, 		// userId
				OperationLogService.OBJECT_TYPE_USER, // objectType
				getId(), 
				null, 
				null, 
				null);
	}

	public static User adapt(UserEntity entity) {
		if (entity == null)
			return null;

		User bean = new User();
		BeanUtils.copyProperties(entity, bean);
		return bean;
	}

	public UserEntity toEntity() {
		return this;
	}

	public String getObjectName() {
		return getName();
	}

	public String getObjectSummary() {
		return this.getName() + ", " + this.getEmail();
	}
}
